
import java.util.Scanner;

//TIP 要<b>运行</b>代码，请按 <shortcut actionId="Run"/> 或
// 点击装订区域中的 <icon src="AllIcons.Actions.Execute"/> 图标。
class TreeNode{
    public char val;
    public TreeNode left;
    public TreeNode right;
    public TreeNode (char val){
        this.val=val;
    }
}
public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        // 注意 hasNext 和 hasNextLine 的区别
        while (in.hasNextLine()) { // 注意 while 处理多个 case
            String s=in.nextLine();
            Main main = new Main();
            TreeNode root = main.creatTree(s);
            main.inOrder(root);
        }
        }
        public int i=0;
    public TreeNode creatTree(String s){
      TreeNode root=null;
        if(s.charAt(i)!='#'){
            root=new TreeNode(s.charAt(i));
            i++;
            root.left=creatTree(s);
            root.right=creatTree(s);
        }else {
            i++;
        }
        return root;
    }
    public void inOrder(TreeNode root){
        if (root ==null){
            return;
        }
        inOrder(root.left);
        System.out.println(root.val+" ");
        inOrder(root.right);
    }

    }
